package _17作业._并发包编程题.t2;

import java.util.concurrent.Semaphore;

public class T2 {
    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            new Thread(new Travel()).start();
        }
    }
}
class Travel implements Runnable{
    static Semaphore semaphore =new Semaphore(3);
    @Override
    public void run() {
        String name = Thread.currentThread().getName();
        try {
            semaphore.acquire();//获取凭证
            System.out.println(name+"开始参观");
            Thread.sleep(2000);
            System.out.println(name+"参观结束，离开展览室");
            semaphore.release();
        }catch (Exception e){
            e.printStackTrace();
        }

    }
}
